package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.otd.pojo.OtdPlanChangeApplyAddVO;
import com.yunxi.otd.pojo.OtdPlanChangeApplyEditVO;
import com.yunxi.otd.pojo.OtdPlanChangeApplyQueryVO;
import com.yunxi.otd.pojo.OtdPlanChangeApplyVO;
import com.yunxi.otd.pojo.VehicleCanChangePlanQueryVO;
import com.yunxi.otd.service.OtdChangeApplyDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 生产计划变更申请 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-05-09
 */
@RestController
@RequestMapping("/admin/otd/apply")
@Api(tags = "OTD:APPLY", description = "生产计划变更申请")
public class OtdChangeApplyController {

    @Autowired
    OtdChangeApplyDubboService applyDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "主页查询")
    public ApiResult page(OtdPlanChangeApplyQueryVO queryVO, Integer pageNum, Integer pageSize) {
        return ResponseUtil.ok(applyDubboService.pageByVo(queryVO, pageNum, pageSize));
    }

    @GetMapping("/plan")
    @ApiOperation(value = "查询可变更的生产计划")
    public ApiResult plan(VehicleCanChangePlanQueryVO queryVO, Integer pageNum, Integer pageSize) {
        return ResponseUtil.ok(applyDubboService.findChangePlan(queryVO, pageNum, pageSize));
    }

    @GetMapping("/getPlan")
    @ApiOperation(value = "根据PlanNo查询生产计划")
    public ApiResult getPlanByPlanNo(String planNo) {
        return ResponseUtil.ok(applyDubboService.findPlanByPlanNo(planNo));
    }

    @GetMapping("/load")
    @ApiOperation(value = "单条查询")
    public ApiResult load(String applyId) {
        return ResponseUtil.ok(applyDubboService.load(applyId));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增变更申请")
    public ApiResult add(@RequestBody OtdPlanChangeApplyAddVO addVO) {
        return applyDubboService.addApply(addVO);
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除变更申请")
    public ApiResult remove(@RequestBody List<String> ids) {
        return applyDubboService.removeByIds(ids);
    }

    @PostMapping("/modify")
    @ApiOperation(value = "编辑")
    public ApiResult modifyApply(@RequestBody OtdPlanChangeApplyEditVO editVO) {
        return applyDubboService.modifyApply(editVO);
    }

    @PostMapping("/reject")
    @ApiOperation(value = "驳回变更申请")
    public ApiResult rejectApply(@RequestBody OtdPlanChangeApplyVO changeApplyVO, @CurrentUser LoginInfo info) {
        return applyDubboService.rejectApply(changeApplyVO, info);
    }

    @PostMapping("/audit")
    @ApiOperation(value = "通过变更申请")
    public ApiResult auditApply(@RequestBody String applyId, @CurrentUser LoginInfo info) {
        return applyDubboService.auditApply(applyId, info);
    }

    @PostMapping("/release")
    @ApiOperation(value = "释放变更申请")
    public ApiResult releaseApply(@RequestBody String applyId, @CurrentUser LoginInfo info) {
        return applyDubboService.releaseApply(applyId, info);
    }

    @GetMapping("/export")
    @ApiOperation(value = "导出")
    public ApiResult export(OtdPlanChangeApplyQueryVO queryVO) {
        return ResponseUtil.ok(applyDubboService.export(queryVO));
    }


}
